/*
 * Timer.cpp
 *
 *  Created on: 17-Dec-2009
 *      Author: pankaj
 */

#include <iostream>
#include "Timer.h"
#include<sys/time.h>
#include<sys/resource.h>

using namespace std;

Timer::Timer()
{
	_istap = false;
}

void Timer::tapTime()
{
	timeval tim;
	gettimeofday(&tim, NULL);
	_tapmark=tim.tv_sec+(tim.tv_usec/1000000.0);
	_istap = true;

}
double Timer::unTapTime()
{
	if(_istap)
	{
		timeval tim;
		//do_something_long();
		gettimeofday(&tim, NULL);
		double t2=tim.tv_sec+(tim.tv_usec/1000000.0);
		//printf("%.6lf seconds elapsed\n", t2-t1);
		return t2-_tapmark;
	}
	return -1;
}
/*
int main()
{
	Timer t;
	t.tapTime();
	//sleep(1);
	for(double i = 0;i < 1000000;i++);

	cout<<t.unTapTime();
}
*/
